"""
统计每天每部门的所有工时，需要根据每个任务的任务日期长度来均分该任务工时

排布计算，每列一个星期，星期一到星期天，从查询起始日期所在星期开始算，
少几天补几天。关键是这补是补空还是全补。如果全补意味着，查询的时间段是近似查询，
只查看星期。这里补空，保证查询的可以看见。


颜色变化：
 R : 0.75 -> 1
 G : 0.75 -> 0.05
 B ：0.75 -> 0
 min : 0
 max : 132 = 11x 12 (合成11个人)
 所以超过132的计算颜色都为 1   0.05  0
    红色变化:
        0.75+0.25* wh/132 =r
    绿色变化:
        0.75-0.7* wh/132 =g
    蓝色变化:
        0.75-0.75* wh/132= b

"""


import os
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import  *
from PyQt5.QtCore import *
from mz_date import MZ_Date
from db_handler import DB_handler
from calendarWindow import Calendar

class ProjectHot(QWidget):

    def __init__(self):
        super(ProjectHot, self).__init__()

        self.max_workhour=132 #最大每天工时上限
        self.btn_font=QFont('',1,12)
        self.btn_style = '''QPushButton{color:black}
                                  QPushButton:hover{color:#FF7F24}
                                  QPushButton{font-size:10px}
                                  QPushButton{background-color:#CFCFCF}
                                  QPushButton{border:0px}
                            '''
        # self.setStyleSheet('background:#CFCFCF')
        self.data_list=[]  #[['2020-10-09',date_data],['2020-10-10',date_data],..]
        self.mz_data=MZ_Date()

    # def init_data(self,start_date,end_date,data_list):
    #     """
    #     分开，不需要具体任务，只需要传入数值即可，因为已经有全局计算的任务了，只会需要要传入日期即可显示对应任务列表
    #     :param start_day:  选择的起始日期
    #     :param end_day:  选择的结束日期
    #     :param proj:  传入该项目的所有数据
    #     :param data_list:[['2020-10-09',20],['2020-10-10',11],..]
    #     :return:
    #     """
    #
    #
    #     if data_list:
    #         self.data_list=data_list
    #         start_date=data_list[0][0]
    #         fill_count = self.get_fill_count(start_date)
    #         print('fill_count:',fill_count)
    #         if fill_count:  #填充日期
    #             for i in range(fill_count):
    #                 self.data_list.insert(0,[])
    #
    #         clips=self.clip_list(data_list,7) #7天7天的拆分
    #         columns_list=self.get_pos(clips) #获取对应坐标
    #
    #         counts=len(data_list)
    #         g_data = self.data_generator(data_list)
    #         rect_size=25
    #         for plist in columns_list:
    #             for pos in plist:
    #                 x,y=pos
    #                 data = next(g_data, None)#['2020-10-09',{'artist1':task_data_list1,'artist2':task_data_list2,'artist3':task_data_list3}] 每个人该日的所有任务
    #                 #task_data_list1=[{'show_workhour':'12'},{'show_workhour':'2'},{'show_workhour':'3'},{'show_workhour':'4'}]
    #                 all_workhour=0
    #                 # print(data[1])
    #                 if data:
    #                     # print(data)
    #                     for v in data[1].values():
    #                         for t in v:
    #                             # print(t)
    #                             show_workhour=t['show_workhour']
    #                             all_workhour+=float(show_workhour)
    #                 all_workhour=round(all_workhour,2)
    #                 btn=QPushButton(str(all_workhour) if data else '-',self) #日期
    #                 btn.setToolTip(data[0] if data else '-' )
    #                 # btn.setFont(self.btn_font)
    #                 r,g,b=self.get_color(all_workhour,self.max_workhour)
    #                 # print(r,g,b)
    #                 btn_style = "QPushButton{color:black}"\
    #                             "QPushButton:hover{color:#FF7F24}"\
    #                              "QPushButton{font-size:10px}" \
    #                             "QPushButton{border:0px}"+"QPushButton{background-color:"+'rgb({}%,{}%,{}%)'.format(r,g,b)+"}"#.format('#FF7F24')  #rgb({}%,{}%,{}%)#rgb({},{},{})}rgb({0},{1},{2})
    #                 btn.setStyleSheet("")
    #                 btn.setStyleSheet(btn_style)
    #                 btn.clicked.connect(self._btn_click)
    #                 btn.setGeometry(x*rect_size,y*rect_size,24,24)

    def init_data(self,start_date,data_list):
        """
        分开，不需要具体任务，只需要传入数值即可，因为已经有全局计算的任务了，只会需要要传入日期即可显示对应任务列表
        :param start_day:  选择的起始日期
        :param end_day:  选择的结束日期
        :param proj:  传入该项目的所有数据
        :param data_list:[('2020-10-09',20),[('2020-10-10',11),..]
        :return:
        """


        if data_list:
            self.data_list=data_list
            # start_date=data_list[0][0]  #获取传入的第一天
            fill_count = self.get_fill_count(start_date)
            # print('fill_count:',fill_count)
            if fill_count:  #填充日期
                for i in range(fill_count):
                    self.data_list.insert(0,[])
            # print('init_data 002')
            clips=self.clip_list(data_list,7) #7天7天的拆分
            # print('init_data 003')
            # print('clips:',clips)
            columns_list=self.get_pos(clips) #获取对应坐标
            # print('columns_list:',columns_list)
            # print('init_data 004')
            counts=len(data_list)
            g_data = self.data_generator(data_list)
            # print('init_data 005')
            rect_size=25
            for plist in columns_list:
                for pos in plist:
                    x,y=pos
                    # print('init_data 005.1')
                    data = next(g_data, None)#('2020-10-09',)每个人该日的所有任务
                    # print('init_data 006')
                    # print('data:',data)
                    all_workhour=round(data[1],2) if data else 0
                    # print('init_data 007')
                    btn=QPushButton(str(all_workhour) if data else '-',self) #日期
                    btn.setToolTip(data[0] if data else '-' )
                    # btn.setFont(self.btn_font)
                    # print('init_data 008')
                    r,g,b=self.get_color(all_workhour,self.max_workhour)
                    # print('init_data 009')
                    # print(r,g,b)
                    btn_style = "QPushButton{color:black}"\
                                "QPushButton:hover{color:#FF7F24}"\
                                 "QPushButton{font-size:10px}" \
                                "QPushButton{border:0px}"+"QPushButton{background-color:"+'rgb({}%,{}%,{}%)'.format(r,g,b)+"}"#.format('#FF7F24')  #rgb({}%,{}%,{}%)#rgb({},{},{})}rgb({0},{1},{2})
                    btn.setStyleSheet("")
                    btn.setStyleSheet(btn_style)
                    btn.clicked.connect(self._btn_click)
                    btn.setGeometry(x*rect_size,y*rect_size,24,24)

    def _btn_click(self):
        btn=self.sender()
        date=btn.toolTip()
        print('选择了该天:',date)

    def data_generator(self,data_list):
        i=0
        while i< len(data_list):#+1
            # print('len data_list:',len(data_list),i)
            yield data_list[i]
            i+=1
            if i>len(data_list):
                break

    def get_color(self,all_workhour,max_workhour):
        """
        根据传来的值来计算rgb值
        颜色变化：
         R : 0.75 -> 1
         G : 0.75 -> 0.05
         B ：0.75 -> 0
         min : 0
         max : 132 = 11x 12 (合成11个人)
         所以超过132的计算颜色都为 1   0.05  0
        红色变化:
            0.75+0.25* wh/132 =r
        绿色变化:
            0.75-0.7* wh/132 =g
        蓝色变化:
            0.75-0.75* wh/132= b

        :param all_workhour:
        :param max_workhour: 最大每天工时上限
        :return:
        """
        all_workhour =all_workhour if all_workhour <=self.max_workhour else self.max_workhour
        r=0.92+0.08* all_workhour/132
        g=0.92-0.7* all_workhour/132
        b= 0.92-2*0.95* all_workhour/132#添加2倍系数，加快衰减
        b=b if b>0 else 0
        return r*100,g*100,b*100

    def get_fill_count(self,start_date):
        """
        根据传入的日期来获取不填数量
        :param start_date:
        :return:
        """
        year, month, day = start_date.split('-')
        weekday = self.mz_data.getWeekday(int(year), int(month), int(day))
        return weekday-1  #填充的数 -1天



    def clip_list(self,a,c):  #a为原列表，c为等分长度
        clip_back=[]
        if len(a)>c:
            for i in range(int(len(a) / c)):
                # print(i)
                clip_a = a[c * i:c * (i + 1)]
                clip_back.append(clip_a)
                # print(clip_a)
            # last 剩下的单独为一组
            last = a[int(len(a) / c) * c:]
            if last:
                clip_back.append(last)
        else:  #如果切分长度不小于原列表长度，那么直接返回原列表
            # clip_back = a
            clip_back.append(a)
        return clip_back

    def get_pos(self,c_list):
        """
        传入切分好的列表，生成坐标
        :param c_list: [[['2020-10-09',date_data],['2020-10-10',date_data],共七个],[七个]]
        :param fill_count :填充的起始数量，因为有可能选择的起始日期不是星期一
        :return: [[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6)],
        [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6)],..]
        """
        all_column=[]
        # if fill_count>0:
        #     for i in range(fill_count):
        #         c_list.insert(0,[])
        # print('len c_list:',len(c_list))
        # print(c_list)
        for x in range(len(c_list)):
            ls=c_list[x]
            per_column=[]
            # for y in range(len(ls)):
            for y in range(7):
                pos=(x,y)
                per_column.append(pos)
            all_column.append(per_column)

        return all_column

class ProjectHotWindow(QWidget):

    def __init__(self,select_start_date=None,select_end_date=None):
        super(ProjectHotWindow, self).__init__()
        self.mz_date=MZ_Date()
        today=self.mz_date.getToday()
        self.select_start_date= select_start_date if select_start_date else today
        self.select_end_date= select_end_date if select_end_date else today
        self.select_data_list=[]  #选择的日期范围之间的所有日期列表
        self.all_department_checkbox=[]
        self.selected_departments=[]  #
        self.department_per_project_map={}  #{}{'01美术':{'proj_ylm':[task1,task2,...],'02模型':{'proj_ylm':[task1,task2,task3...],...}}
        self.slipt_department_per_project_map={}  #拆分每一天后的部门-项目-task map信息

        self.handler = DB_handler()
        self.db_project_name_map=self.handler.project_map #{'proj_gjwd': ['古剑网大', 'GJWD'], 'proj_xmm': ['致我们甜甜的小美满_BJ', 'XMM'],
        self.btn_style='''QPushButton{color:black}
                                  QPushButton:hover{color:#FF7F24}
                                  QPushButton{background-color:#CFCFCF}
                                  QPushButton{border:2px}
                                  QPushButton{border-radius:10px}
                                  QPushButton{padding:5px 1px}'''
        self.clear_btn_style='''QPushButton{color:black}
                                  QPushButton:hover{color:#FF7F24}
                                  QPushButton{background-color:#CFCFCF}
                                  QPushButton{border:15px}
                                  QPushButton{border-radius:10px}
                                  QPushButton{padding:5px 1px}'''
        self.check_style = '''QCheckbox:hover{color :##FF7F24}
                              QCheckbox{background-color:#CFCFCF}
                              QCheckbox{padding:1px 1px}
                                '''
        self.setWindowFlags(Qt.WindowStaysOnTopHint)
        self.sicon = QIcon('bu.png')
        self.setWindowIcon(self.sicon)
        self.project_font=QFont('',13,65)
        self.setWindowTitle('各部门各项目日历')
        self.setMinimumWidth(1000)
        self.main_layout=QHBoxLayout()

        self.left_layout=QVBoxLayout()
        self.date_layout=QVBoxLayout()
        self.date_layout.setAlignment(Qt.AlignTop)
        self.date_layout.setContentsMargins(0,30,0,0)
        self.date_layout.setSpacing(12)
        self.start_date_btn=QPushButton(self.select_start_date)
        self.start_date_btn.setStyleSheet(self.btn_style)
        self.start_date_btn.clicked.connect(self._choose_startday)
        self.end_date_btn=QPushButton(self.select_end_date)
        self.end_date_btn.setStyleSheet(self.btn_style)
        self.end_date_btn.clicked.connect(self._choose_endday)
        self.OK_btn=QPushButton('确认')
        self.OK_btn.setStyleSheet(self.btn_style)
        self.OK_btn.clicked.connect(self._get_all_data)
        self.date_layout.addWidget(self.start_date_btn)
        self.date_layout.addWidget(self.end_date_btn)
        self.date_layout.addWidget(self.OK_btn)
        self.quick_layout=QVBoxLayout()
        self.quick_layout.setSpacing(12)
        self.quick_layout.setAlignment(Qt.AlignTop)
        self.quick_layout.setContentsMargins(0,20,0,0)
        self.last_month_btn=QPushButton('上月')
        self.last_month_btn.setStyleSheet(self.btn_style)
        self.last_month_btn.clicked.connect(self._set_last_month)
        self.this_month_btn=QPushButton('本月')
        self.this_month_btn.setStyleSheet(self.btn_style)
        self.this_month_btn.clicked.connect(self._set_current_month)
        self.next_month_btn=QPushButton('下月')
        self.next_month_btn.setStyleSheet(self.btn_style)
        self.next_month_btn.clicked.connect(self._set_next_month)
        self.last_week_btn=QPushButton('上周')
        self.last_week_btn.setStyleSheet(self.btn_style)
        self.last_week_btn.clicked.connect(self._set_last_week)
        self.this_week_btn=QPushButton('本周')
        self.this_week_btn.setStyleSheet(self.btn_style)
        self.this_week_btn.clicked.connect(self._set_current_week)
        self.next_week_btn=QPushButton('下周')
        self.next_week_btn.setStyleSheet(self.btn_style)
        self.next_week_btn.clicked.connect(self._set_next_week)

        self.quick_layout.addWidget(self.last_month_btn)
        self.quick_layout.addWidget(self.this_month_btn)
        self.quick_layout.addWidget(self.next_month_btn)
        self.quick_layout.addWidget(self.last_week_btn)
        self.quick_layout.addWidget(self.this_week_btn)
        self.quick_layout.addWidget(self.next_week_btn)

        self.date_layout.addWidget(self.start_date_btn)
        self.date_layout.addWidget(self.end_date_btn)
        self.department_layout=QVBoxLayout()
        self.department_layout.setAlignment(Qt.AlignTop)
        self.department_layout.setContentsMargins(0,50,0,30)
        self.clear_btn=QPushButton('清空')
        self.clear_btn.setStyleSheet(self.clear_btn_style)
        self.clear_btn.clicked.connect(self._clear_checkbox)
        self.department_layout.addWidget(self.clear_btn)
        self.init_deparments()
        self.left_layout.addLayout(self.date_layout)
        self.left_layout.addLayout(self.quick_layout)
        self.left_layout.addLayout(self.department_layout)

        self.hs = QSplitter(Qt.Horizontal)
        self.hs.setStyleSheet('QSplitter::handle { background-color: #CFCFCF }')
        self.sc = QScrollArea()
        self.sc.setStyleSheet('QScrollBar{width:5px}')
        self.mid_frame=QFrame()#QWidget()#QScrollArea()#QFrame()
        self.mid_frame.setMinimumHeight(5500)
        self.mid_frame.setMinimumWidth(3000)
        self.mid_layout=QVBoxLayout()
        self.mid_layout.setAlignment(Qt.AlignTop)
        self.mid_frame.setLayout(self.mid_layout)
        self.sc.setWidget(self.mid_frame)

        # self.right_layout=QVBoxLayout()
        # self.task_list=QListWidget()
        # self.task_list.setMinimumWidth(30)
        self.help=QTextBrowser()
        self.help.setMinimumWidth(30)
        self.init_help()
        self.hs.addWidget(self.sc)
        # self.hs.addWidget(self.task_list)
        self.hs.addWidget(self.help)
        self.hs.setStretchFactor(0, 8)
        self.hs.setStretchFactor(1, 2)
        self.main_layout.addLayout(self.left_layout)
        # self.main_layout.addWidget(self.sc)
        # self.main_layout.addWidget(self.hs)
        # self.main_layout.addLayout(self.right_layout)
        self.main_layout.addWidget(self.hs)
        self.setLayout(self.main_layout)


    def _clear_mid_frame(self):
        if self.mid_frame.children():
            for i in self.mid_frame.children():
                if isinstance(i, ProjectHot) or isinstance(i, QLabel):
                    i.deleteLater()

    def _get_all_data(self):
        """
        获取选定日期内的所有信息
        :return:
        """
        start_day=self.start_date_btn.text()
        end_day =self.end_date_btn.text()
        delta=self.mz_date.delta_date(start_day,end_day)

        self.select_start_date=start_day if delta> 0 else end_day
        self.select_end_date=end_day if delta> 0 else start_day
        # print('self.select_start_date,self.select_end_date:',self.select_start_date,self.select_end_date)
        self.select_data_list = self.mz_date.getAlldaysInStartEndDay(self.select_start_date,
                                                                     self.select_end_date)  # 获取日期列表

        # print('mid_layout.children:',self.mid_frame.children())
        self._clear_mid_frame()

        # print('_get_all_data 003:')
        try:
            all_task_info_list=self.handler.select_task_in_dates(self.select_start_date,self.select_end_date)
        except Exception as _get_all_data_ERR:
            print('_get_all_data_ERR:', str(_get_all_data_ERR))
        if all_task_info_list:
            # print('_get_all_data 003.1:')

            self.department_per_project_map=self.handler.get_all_department_per_project_map(all_task_info_list)#
            print('department_per_project_map:',self.department_per_project_map['01美术'])
            ms=self.department_per_project_map['01美术']
            for k ,v in ms.items():
                print(k,v)
            # print('self.department_per_project_map keys:',self.department_per_project_map.keys())
            # print('_get_all_data 003.2:')
            all_splited_tasks = self.handler.split_all_tasks(all_task_info_list)
            # print('_get_all_data 003.3:')
            # print('all_splited_tasks:',all_splited_tasks)
            # for ast in all_splited_tasks:
                # if ast['artist']=='张洲':
                #     print('ast:',ast)
            self.slipt_department_per_project_map=self.handler.get_all_department_per_project_map(all_splited_tasks)#
            # print('_get_all_data 004:')
            try:
                self._show_hot(self.selected_departments,self.slipt_department_per_project_map)
            except Exception as _show_hot_ERR:
                print('_show_hot_ERR:',str(_show_hot_ERR))



    def _show_hot(self,departments,department_per_project_map):
        """
        传入选择的部门，传入获取到的所有部门-项目-任务信息
        :param departments: ['01美术','02跟踪']
        :param department_per_project_map: {'01美术':{'proj_ylm':[task1,task2,...],'02模型':{'proj_ylm':[task1,task2,task3...],...}}
        :return:
        """
        # print('_show_hot001')
        # print('departments:',departments)
        # print('department_per_project_map:',department_per_project_map)
        all_project_task_map={}  # all_project_task_map : {'项目名称1':[task1,task2,],'项目名称2':[task1,task2,],...}
        for dep in departments:
            per_project_data=department_per_project_map.get(dep,None)
            # assert per_project_data is not None, QMessageBox.information(None,'提示','该时间段没有项目内容')
            if per_project_data:
                # print('per_project_data keys:',per_project_data.keys())
                for db,task_list in per_project_data.items():
                    # print('db,task_list:',db,task_list)
                    if db not in all_project_task_map.keys():
                        # print('self.db_project_name_map:',self.db_project_name_map)
                        full_name,entity_name=self.db_project_name_map.get(db,['非制作项目','NWK'])  #所有不在数据库里面的都算非制作项目
                        project_name='{}\n{}'.format(full_name,entity_name)
                        # print('project_name:',project_name)
                        all_project_task_map[project_name]=task_list  #以项目名称显示而不是数据库名称
                    else:
                        full_name,entity_name = self.db_project_name_map.get(db, ['非制作项目','NWK'])
                        project_name = '{}\n{}'.format(full_name, entity_name)
                        all_project_task_map[project_name].extend(task_list)

        # print('all_project_task_map:',all_project_task_map)
        # print('all_project_task_map keys:',all_project_task_map.keys())
        if all_project_task_map:
            for depart,tasks in all_project_task_map.items():  #计算每个项目的所有选择日期内，每一天的总工时
                hot=self._create_hot(depart)
                # print('_show_hot 005')
                hot_data=self._get_hot_data(tasks)
                # print('_show_hot 006')
                hot.init_data(self.select_start_date,hot_data)
                # print('_show_hot 007')

    def _create_hot(self,project_name):
        """
        创建一个hot组件，同时加入到self.mid_layout,返回该hot
        :param:project_name 项目名称。给Label显示用的
        :return: hot
        """
        hot=ProjectHot()
        project_label=QLabel(project_name)
        project_label.setFont(self.project_font)
        project_label.setMaximumWidth(130)
        project_label.setStyleSheet('background:#CFCFCF')
        project_label.setAlignment(Qt.AlignCenter)
        project_label.setMinimumHeight(173)
        per_hot_layout=QHBoxLayout()
        per_hot_layout.setSpacing(0)
        per_hot_layout.setAlignment(Qt.AlignTop)
        per_hot_layout.addWidget(project_label)
        per_hot_layout.addWidget(hot)
        self.mid_layout.addLayout(per_hot_layout)
        return hot

    def _get_hot_data(self,tasks_list):
        """
        传入所有任务列表，通过选择的日期长度，来填充每天的总工时
        :param tasks_list:
        :return: [('2020-11-20':0),('2020-11-21':24),..] 指定日期内的每天总工时列表
        """
        date_workhour_list=[]
        for date in self.select_data_list:
            the_date_all_workhour =0  #该日期内所有总工时
            for task in tasks_list:
                one_date=task['one_date']
                one_date_workhour=task['one_date_workhour']
                if one_date==date:
                    the_date_all_workhour+=one_date_workhour
            date_workhour_list.append((date,the_date_all_workhour))
        return date_workhour_list

    #日期选择
    def _choose_startday(self):
        self.calender=Calendar()
        self.calender.dateSignal.connect(self._set_startday)
        self.calender.show()

    def _set_startday(self,date):
        self.select_start_date=date
        self.start_date_btn.setText(date)

    def _choose_endday(self):
        self.calender=Calendar()
        self.calender.dateSignal.connect(self._set_endday)
        self.calender.show()

    def _set_endday(self,date):
        self.select_end_date=date
        self.end_date_btn.setText(date)

    #设置日期
    def _set_last_week(self):
        self.select_start_date,self.select_end_date=self.mz_date.get_last_week()
        self.select_data_list=self.mz_date.getAlldaysInStartEndDay(self.select_start_date,self.select_end_date)
        self.start_date_btn.setText(self.select_start_date)
        self.end_date_btn.setText(self.select_end_date)
        self._get_all_data()

    def _set_current_week(self):
        self.select_start_date,self.select_end_date=self.mz_date.get_current_week()
        self.select_data_list=self.mz_date.getAlldaysInStartEndDay(self.select_start_date,self.select_end_date)
        self.start_date_btn.setText(self.select_start_date)
        self.end_date_btn.setText(self.select_end_date)
        self._get_all_data()

    def _set_next_week(self):
        self.select_start_date,self.select_end_date=self.mz_date.get_next_week()
        self.select_data_list=self.mz_date.getAlldaysInStartEndDay(self.select_start_date,self.select_end_date)
        self.start_date_btn.setText(self.select_start_date)
        self.end_date_btn.setText(self.select_end_date)
        self._get_all_data()


    def _set_last_month(self):
        self.select_start_date,self.select_end_date=self.mz_date.get_last_month()
        self.select_data_list=self.mz_date.getAlldaysInStartEndDay(self.select_start_date,self.select_end_date)
        self.start_date_btn.setText(self.select_start_date)
        self.end_date_btn.setText(self.select_end_date)
        self._get_all_data()

    def _set_current_month(self):
        self.select_start_date,self.select_end_date=self.mz_date.get_current_month()
        self.select_data_list=self.mz_date.getAlldaysInStartEndDay(self.select_start_date,self.select_end_date)
        self.start_date_btn.setText(self.select_start_date)
        self.end_date_btn.setText(self.select_end_date)
        self._get_all_data()

    def _set_next_month(self):
        self.select_start_date,self.select_end_date=self.mz_date.get_next_month()
        self.select_data_list=self.mz_date.getAlldaysInStartEndDay(self.select_start_date,self.select_end_date)
        self.start_date_btn.setText(self.select_start_date)
        self.end_date_btn.setText(self.select_end_date)
        self._get_all_data()

    def init_deparments(self):
        departments=['01美术','02模型','03跟踪','04动画','05场景','06灯光','07特效一','07特效二','08合成一','08合成二',
        '09包装','10剪辑','11调色','12TD','13虚拟']
        for i in departments:
            checkbox=QCheckBox(i)
            checkbox.setStyleSheet("QCheckBox:hover{color:#FF7F24}"
                                   "QCheckBox{border-radius:5px}"
                                   "QCheckBox{background-color:#CFCFCF}")
            checkbox.stateChanged.connect(self.choose)

            self.all_department_checkbox.append(checkbox)
            self.department_layout.addWidget(checkbox)

    def choose(self):
        """
        选择部门
        :return:
        """
        selected_department=[]
        for i in self.all_department_checkbox:
            if i.isChecked():
                selected_department.append(i.text())
        print(selected_department)
        self._clear_mid_frame()
        self.selected_departments=selected_department
        if self.slipt_department_per_project_map:
            self._show_hot(self.selected_departments,self.slipt_department_per_project_map)


    def _clear_checkbox(self):
        for i in self.all_department_checkbox:
            i.setCheckState(Qt.Unchecked)
        self.selected_departments=[]


    def init_help(self):
        text='说明:\n\n' \
             '切换日期后需要点击确认，快捷日期按钮点击后自动确认，\n\n' \
             '可以多项部门综合显示，\n\n' \
             '包含历史数据,关闭任务以及包括离职人员任务'
        self.help.setText(text)



if __name__ == '__main__':
    app=QApplication(sys.argv)
    # p=ProjectHot()
    department='跟踪'
    task_data_list1=[{'show_workhour':'20'},{'show_workhour':'2'},{'show_workhour':'3'},{'show_workhour':'4'}]
    task_data_list2=[{'show_workhour':'0'},{'show_workhour':'0'},{'show_workhour':'1'},{'show_workhour':'0'}]
    task_data_list3=[{'show_workhour':'1'},{'show_workhour':'2'},{'show_workhour':'3'},{'show_workhour':'4'}]
    task_data_list4=[{'show_workhour':'1'},{'show_workhour':'2'},{'show_workhour':'1'},{'show_workhour':'1'}]
    task_data_list5=[{'show_workhour':'3'},{'show_workhour':'2'},{'show_workhour':'3'},{'show_workhour':'4'}]

    data_list=[['2020-10-09',{'artist1':task_data_list1,'artist2':task_data_list2,'artist3':task_data_list3}],
               ['2020-10-10',{'artist1':task_data_list1,'artist2':task_data_list1,'artist3':task_data_list1}],
               ['2020-10-11',{'artist1':task_data_list2,'artist2':task_data_list2,'artist3':task_data_list3}],
               ['2020-10-12',{'artist1':task_data_list1,'artist2':task_data_list3,'artist3':task_data_list1}],
                ['2020-10-13',{'artist1':task_data_list1,'artist2':task_data_list1,'artist3':task_data_list3}],
               ['2020-10-14',{'artist1':task_data_list1,'artist2':task_data_list2,'artist3':task_data_list1}],
               ['2020-10-15',{'artist1':task_data_list3,'artist2':task_data_list3,'artist3':task_data_list3}],
               ['2020-10-16',{'artist1':task_data_list2,'artist2':task_data_list2,'artist3':task_data_list2}]]
    # p.init_data(data_list)
    # p.show()

    w=ProjectHotWindow()
    w.show()

    sys.exit(app.exec_())